import redis
from rest_framework.response import Response
from ronglian_sms_sdk import SmsSDK
import json


accId = '8aaf070881ad8ad401821a40d4681bc2'
accToken = 'e48a263a40534fd68f3c20c8a602e408'
appId = '8aaf070881ad8ad401821a40d54a1bc9'

def send_sms_code(mobile,data):
    sdk = SmsSDK(accId=accId,accToken=accToken,appId=appId)
    tid = "1"
    datas = (data,)
    resp = sdk.sendMessage(tid,mobile,datas)
    if resp == "000000" or resp == "112310":
        r = redis.Redis()
        r.setex("sms_%s" % mobile, 600, data)
        return Response({"code": 200, "msg": "发送成功"})
    else:
        return Response({"code": 400, "msg": "发送失败"})

